import JSEncrypt from 'jsencrypt'

const PUB_KET =
	'-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1QQRl0HlrVv6kGqhgonD6A9SU6ZJpnEN+Q0blT/ue6Ndt97WRfxtSAs0QoquTreaDtfC4RRX4o+CU6BTuHLUm+eSvxZS9TzbwoYZq7ObbQAZAY+SYDgAA5PHf1wNN20dGMFFgVS/y0ZWvv1UNa2laEz0I8Vmr5ZlzIn88GkmSiQIDAQAB-----END PUBLIC KEY-----'
const PRI_KEY =
	'-----BEGIN RSA PRIVATE KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDd8bqiWK6kD9vIwyuBMW70Ha9VwB+w533ZbP08V5SGmsiaoXnScL5q3YYC8gnsk8un5pH2Xx4znXEFNTM+qYENIvGVM0HkpySNfQ7+qaOxWmCEFjlqmBqknei7Efk5Sn4i5ZuXe/2/rbUszDP2ZrusaCqquerYpJEJqo/Q5XokUQIDAQAB-----END RSA PRIVATE KEY----'

// RSA加密
export const rsaEncrypt = (text) => {
	const encryptor = new JSEncrypt() // 创建加密对象实例
	//之前ssl生成的公钥，复制的时候要小心不要有空格
	encryptor.setPrivateKey(PRI_KEY) //设置公钥
	const rsaPassWord = encryptor.encrypt(text) // 对内容进行加密
	return rsaPassWord;
}

// RSA 解密
export const rsaDecrypt = (enText) => {
	const decrypt = new JSEncrypt() //创建解密对象实例
	//之前ssl生成的秘钥
	decrypt.setPrivateKey(PRI_KEY) //设置秘钥
	const uncrypted = decrypt.decrypt(enText) //解密之前拿公钥加密的内容
	return uncrypted;
}